#include <tenacitas.log/text_line.h>

using namespace tenacitas::log;

// -----------------------------------------------------------------------------
const std::string &
text_line::
get_header( ) {

    static const std::string l_text_log_identifier = "tenacitas::log::text_line";

    return l_text_log_identifier;                
}


// -----------------------------------------------------------------------------
bool
text_line::
get_timestamp( uint64_t & p_timestamp ) const {
    bool l_rc = false;
    try {
                    
        size_t l_pos1 = m_line.find('|');
        if ( l_pos1 != std::string::npos ) {
            size_t l_pos2 = m_line.find( '|', l_pos1 + 1 );
            if ( l_pos2 != std::string::npos ) {
                std::string l_timestamp = m_line.substr( l_pos1 + 1,
                                                         l_pos2 - l_pos1 );
                p_timestamp = std::stoull( l_timestamp );
                l_rc = true;
            }
        }
    }                
    catch ( std::exception & l_ex ) {
        std::cerr << "Error at " 
                  << __FILE__ << ", "
                  << __func__ << ", "
                  << __LINE__ << ": "
                  << "error retrieving time-stamp from line '"
                  << m_line << "': "
                  << l_ex.what( ) << std::endl;
                    
        tenacitas::exception::exception l_ten_ex =
            make_tenacitas_exception( l_ex.what( ) );
                    
        throw l_ten_ex;
    }                
    return l_rc;
}
